<?php
/**
 * Copyright (c) [2019] [吴跃忠]
 * [selibra] is licensed under the Mulan PSL v1.
 * You can use this software according to the terms and conditions of the Mulan PSL v1.
 * You may obtain a copy of Mulan PSL v1 at:
 * http://license.coscl.org.cn/MulanPSL
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v1 for more details.
 */

namespace Selibra\Http\Annotations;


use Selibra\CommonIntf\OutputStringIntf;
use Selibra\Di\AnnotationConfigure;
use Selibra\Di\AnnotationExecEntity;
use Selibra\Di\Annotations\Protocol\SelibraAnnotationInterface;
use \Attribute;
use Selibra\Di\DI;
use Selibra\Http\Route\ControllerBaseRouteMapper;
use Selibra\Tools\Console;

/**
 * HTTP请求控制器Annotation，注解表示注解类是一个HTTP请求控制器对象
 */
#[Attribute(Attribute::TARGET_CLASS)]
final class Controller implements SelibraAnnotationInterface
{

    /**
     * @var string
     */
    protected string $controllerBaseRoute;


    /**
     * Controller constructor.
     * @param string $route
     */
    public function __construct(string $route = '/', string $baseRoute = null)
    {
        if (!is_null($route) && class_exists($route)) {
            $route = $route::outputString();
        }
        if (!is_null($baseRoute) && class_exists($baseRoute)) {
            $baseRoute = $baseRoute::outputString();
        }
        $this->controllerBaseRoute = $baseRoute . $route;
    }


    /**
     * @inheritDoc
     */
    public function exec(AnnotationExecEntity &$annotationExecEntity)
    {
        ControllerBaseRouteMapper::add($annotationExecEntity->getClass(), $this->controllerBaseRoute);
    }


    /**
     * @inheritDoc
     */
    public function configure(AnnotationConfigure $annotationConfigure)
    {
    }
}